'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:AttendanceAttendanceDepsCtrl
 * @description
 * # AttendanceAttendanceDepsCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('AttendanceAttendanceDepsCtrl', function(DataService, Util, openApi, localStorageService, $routeParams) {
        var vm = this;
        var attDetail = localStorageService.get("attDetail") || {};
        this.peoplelist = [];
        var userArr = []
        var init = function() {
            var param = {};
            param.acId = $routeParams.id;
            DataService.getData(openApi.attSelectdepartment, param).then(function(data) {
                vm.deplist = data;
                userArr = vm.deplist.forEach(function(item, index) {
                    if (item.name == 2||attDetail.department&&attDetail.department.indexOf(item.value)>-1) {
                        item.selected = true;
                    }
                })
                console.log(data)
            })
        }
        this.checkItem = function(disabled) {
            if (disabled == 1) {
                Util.Toast("当前部门已经在考勤当中");
            }
        };
        this.confirm = function() {
            userArr = vm.deplist.filter(function(item, index) {
                return item.selected;
            })
            attDetail.department = userArr.map(function(item, index) {
                return item.value
            })
            attDetail.departments = userArr.map(function(item, index) {
                return item.text
            }).toString();
            localStorageService.set("attDetail", attDetail);
            Util.goBack();
        }
        init()
    });